//DevNETCoder
//CopyRight By DevNET Group
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;
 
namespace STT.Business
{
    public class BTbHocVien_NgoaiNgu
    {
//-----------------------------------------------------------//
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHocVien_NgoaiNgu_SelectAll", null);
            return all;
        }
        public static DataTable SelectTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHocVien_NgoaiNgu_SelectTop", pr);
            return all;
        }
        public static DataTable SelectByMaHV(string MaHV)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaHV", MaHV);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHocVien_NgoaiNgu_SelectByMaHV", pr);
            return all;
        }
        //SelectByMaHV

        //-----------------------------------------------------------//
        public static DataTable SearchHocVienNN(String HVNN)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenHV", HVNN);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHocVienNN_Search", pr);
            return all;
        }
//-----------------------------------------------------------//
        public static void Insert(ETbHocVien_NgoaiNgu OTbHocVien_NgoaiNgu)
        {
            SqlParameter[] pr = new SqlParameter[4];
            pr[0] = new SqlParameter(@"MaHV", OTbHocVien_NgoaiNgu.MaHV);
            pr[1] = new SqlParameter(@"MaNgoaiNgu", OTbHocVien_NgoaiNgu.MaNgoaiNgu);
            pr[2] = new SqlParameter(@"NgayCap", OTbHocVien_NgoaiNgu.NgayCap);
            pr[3] = new SqlParameter(@"NoiCap", OTbHocVien_NgoaiNgu.NoiCap);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbHocVien_NgoaiNgu_Insert", pr);
        }

        
//-----------------------------------------------------------//
        public static void Update(ETbHocVien_NgoaiNgu OTbHocVien_NgoaiNgu)
        {
            SqlParameter[] pr = new SqlParameter[4];
            pr[0] = new SqlParameter(@"MaHV", OTbHocVien_NgoaiNgu.MaHV);
            pr[1] = new SqlParameter(@"MaNgoaiNgu", OTbHocVien_NgoaiNgu.MaNgoaiNgu);
            pr[2] = new SqlParameter(@"NgayCap", OTbHocVien_NgoaiNgu.NgayCap);
            pr[3] = new SqlParameter(@"NoiCap", OTbHocVien_NgoaiNgu.NoiCap);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbHocVien_NgoaiNgu_Update", pr);
        }
//-----------------------------------------------------------//
        public static void Delete(string MaHV,int MaNgoaiNgu)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaHV",MaHV);
            pr[1] = new SqlParameter(@"MaNgoaiNgu",MaNgoaiNgu);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbHocVien_NgoaiNgu_Delete", pr);
        }
//-----------------------------------------------------------//
        public static ETbHocVien_NgoaiNgu SelectByID(string MaHV,int MaNgoaiNgu)
        {
            ETbHocVien_NgoaiNgu OTbHocVien_NgoaiNgu = new ETbHocVien_NgoaiNgu();
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaHV",MaHV);
            pr[1] = new SqlParameter(@"MaNgoaiNgu",MaNgoaiNgu);
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure,"TbHocVien_NgoaiNgu_SelectByID", pr);
            if (idr.Read())
              OTbHocVien_NgoaiNgu = GetOneTbHocVien_NgoaiNgu(idr);
            idr.Close();
            idr.Dispose();
            return OTbHocVien_NgoaiNgu;
        }
        //-----------------------------------------------------------//
        public static bool KiemTraDuLieu(ETbHocVien_NgoaiNgu HVNN)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaHV", HVNN.MaHV);
            pr[1] = new SqlParameter(@"MaNgoaiNgu", HVNN.MaNgoaiNgu);


            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHocVienNN_KiemTraDuLieu", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
//-----------------------------------------------------------//
        private static ETbHocVien_NgoaiNgu GetOneTbHocVien_NgoaiNgu(IDataReader idr)
       {
            ETbHocVien_NgoaiNgu OTbHocVien_NgoaiNgu = new ETbHocVien_NgoaiNgu();
                if (idr["MaHV"] != DBNull.Value)
                    OTbHocVien_NgoaiNgu.MaHV = (string)idr["MaHV"];
                if (idr["MaNgoaiNgu"] != DBNull.Value)
                    OTbHocVien_NgoaiNgu.MaNgoaiNgu = (int)idr["MaNgoaiNgu"];
                if (idr["NgayCap"] != DBNull.Value)
                    OTbHocVien_NgoaiNgu.NgayCap = (DateTime)idr["NgayCap"];
                if (idr["NoiCap"] != DBNull.Value)
                    OTbHocVien_NgoaiNgu.NoiCap = (string)idr["NoiCap"];
            return OTbHocVien_NgoaiNgu;
       }
//-----------------------------------------------------------//
        public static bool TestByID(string MaHV,int MaNgoaiNgu)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaHV",MaHV);
            pr[1] = new SqlParameter(@"MaNgoaiNgu",MaNgoaiNgu);
            pr[2] = new SqlParameter(@"TestID",SqlDbType.Bit);
            pr[2].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbHocVien_NgoaiNgu_TestByID", pr);
            return Convert.ToBoolean(pr[2].Value);
        }
//-----------------------------------------------------------//
        public static List<ETbHocVien_NgoaiNgu> ListAll()
        {
            List<ETbHocVien_NgoaiNgu> list = new List<ETbHocVien_NgoaiNgu>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbHocVien_NgoaiNgu_SelectAll", null);
            while (idr.Read())
              list.Add(GetOneTbHocVien_NgoaiNgu(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }
        public static void DeleteByMaHV(string MaHV)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaHV", MaHV);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbHocVien_NgoaiNgu_DeleteByMaHV", pr);
        }
        public static List<ETbHocVien_NgoaiNgu> ListTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            List<ETbHocVien_NgoaiNgu> list = new List<ETbHocVien_NgoaiNgu>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbHocVien_NgoaiNgu_SelectAll", pr);
            while (idr.Read())
              list.Add(GetOneTbHocVien_NgoaiNgu(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }
    }
 
}